#!/usr/bin/env python

'''
This script moves files in sub directories:
 a* -> a/a*
 A* -> a/A*
 b* -> b/b*

...
'''

import sys,os

def main():
    if sys.argv[1:]:
        os.chdir(sys.argv[1])

    for c in range(ord('a'),ord('z')+1):

        if os.system('ls %c* &> /dev/null'%c) and os.system('ls %c* &> /dev/null'%(c-32)):
            continue

        os.mkdir('_%c'%c)

        os.system('mv %c* %c* _%c &> /dev/null' % (c,c-32,c))

        os.rename('_%c'%c,chr(c))
        print chr(c)


    for c in range(ord('0'),ord('9')+1):

        if os.system('ls %c* &> /dev/null'%c):
            continue

        os.mkdir('_%c'%c)

        os.system('mv %c* _%c &> /dev/null' % (c,c))

        os.rename('_%c'%c,chr(c))
        print chr(c)


if __name__=="__main__":
    main()
